﻿using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Storage.Repositories.Base
{
	public class RepStorage
	{
		private SQLiteAsyncConnection _gymConnection;

		public Repositories.ExerciseLogRep ExerciseLogRepo { get; private set; }
		public Repositories.ExerciseRep ExerciseRepo { get; private set; }
		public Repositories.SetLogRep SetLogRepo { get; private set; }

		public RepStorage()
		{
			_gymConnection = new SQLite.GymLogConnection();

			ExerciseLogRepo = new ExerciseLogRep(_gymConnection);
			ExerciseRepo = new ExerciseRep(_gymConnection);
			SetLogRepo = new SetLogRep(_gymConnection);
		}

		public async Task CreateTables()
		{
			var tables = GetAllReps().Select(x => x.TableType).ToArray();
			await _gymConnection.CreateTablesAsync(tables);
		}

		public IEnumerable<IRep> GetAllReps()
		{
			//add new tables heare
			yield return ExerciseLogRepo;
			yield return ExerciseRepo;
			yield return SetLogRepo;
		}
	}
}
